import 'package:flutter/material.dart';
import 'package:news_demo/Pojo/News_Itme_Pojo.dart';
import 'package:news_demo/View/NewValue/NewValue.dart';

class DelectIndex extends StatefulWidget {
  const DelectIndex({Key? key}) : super(key: key);

  @override
  State<DelectIndex> createState() => _DelectIndexState();
}

class _DelectIndexState extends State<DelectIndex> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0,
        backgroundColor: Colors.white,
        title: Text("历史回收",style: TextStyle(color: Colors.black,fontSize: 24),),
        leading: Container(
          child:GestureDetector(
            onTap: (){
              Navigator.pop(context);
            },
            child: Icon(Icons.arrow_circle_left,color: Colors.blue,size: 40),
          ),
        ),
      ),
      body: DeIndex(),
    );
  }
}

class DeIndex extends StatefulWidget {
  const DeIndex({Key? key}) : super(key: key);

  @override
  State<DeIndex> createState() => _DeIndexState();
}


class _DeIndexState extends State<DeIndex> {
  
  
  List<Widget> WidgetList=[];
  
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    
    List<NewsItmePojo> ArrayLists=[
      NewsItmePojo(
        "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
        "2023/1/2",
        "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
        "某某日报",
        "2",
      ),
      NewsItmePojo(
        "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
        "2023/1/2",
        "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
        "某某日报",
        "2",
      ),
      NewsItmePojo(
        "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
        "2023/1/2",
        "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
        "某某日报",
        "2",
      ),
      NewsItmePojo(
        "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
        "2023/1/2",
        "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
        "某某日报",
        "2",
      ),
    ];
    
    for(int i=0;i<ArrayLists.length;i++){
      WidgetList.add(
        DeItme(NIP: ArrayLists[i])
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Container(
          margin: EdgeInsets.all(8),
          child:Column(
            children: WidgetList,
          )
      ),
    );
  }
}

class DeItme extends StatelessWidget {
  final NewsItmePojo NIP;
  const DeItme({Key? key,required this.NIP}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: (){
        Navigator.push(context, MaterialPageRoute(builder: (context)=>NewValue(NewKey: "0")));
      },
      child: Container(
        margin: EdgeInsets.fromLTRB(0, 0, 0, 8),
        width: double.infinity,
        height: 110,
        decoration: BoxDecoration(
            color: Colors.black26,
            borderRadius: BorderRadius.all(Radius.circular(2))
        ),
        child: Row(
          children: [
            // 图片
            Expanded(
              flex: 3,
              child: Container(
                padding: const EdgeInsets.all(4),
                height: 100,
                child: Image.network(
                  NIP.imageUrl,
                  fit: BoxFit.fill,
                ),
              ),
            ),
            //文字
            Expanded(
              flex: 7,
              child: Container(
                height: 100,
                width: double.infinity,
                child: Column(
                  children: [
                    //标题
                    Expanded(
                      flex: 7,
                      child: Container(
                        padding: const EdgeInsets.all(4),
                        width: double.infinity,
                        //标题
                        child: Text(
                          NIP.titleValue,
                          style: TextStyle(
                              fontWeight: FontWeight.w600,
                              fontSize: 14
                          ),
                        ),
                      ),
                    ),
                    //注释
                    Expanded(
                        flex: 3,
                        child: Container(
                          padding: const EdgeInsets.all(4),
                          width: double.infinity,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              //提供方的信息
                              Container(
                                alignment: Alignment.center,
                                height: double.infinity,
                                //绑定部门
                                child: Text(NIP.department,
                                  style: TextStyle(
                                      fontSize: 14
                                  ),),
                              ),
                              //  日期
                              Container(
                                alignment: Alignment.center,
                                height: double.infinity,
                                margin: const EdgeInsets.fromLTRB(0, 0, 10, 0),
                                //绑定时间
                                child: Text(NIP.timeValue,
                                  style: TextStyle(
                                      fontSize: 14
                                  ),
                                ),
                              ),
                            ],
                          ),
                          // height: ,
                        )
                    ),
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}




